#ifndef __MISC_H__
#define __MISC_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
#include <readline/readline.h>
#include <readline/history.h>

#define CLOSE "\001\033[0m\002" // 关闭所有属性
#define BLOD "\001\033[1m\002" // 强调、加粗、高亮
#define BEGIN(x,y) "\001\033["#x";"#y"m\002" // x: 背景，y: 前景

//词汇表 排列
#define ID 0
#define WORD 1
#define DESCRIPTION 2
#define PRONOUNCE 3
#define PROFICIENCY_LEVEL 4
#define SPELL_LEVEL 5

//阅读表 排列
#define R_ID 0
#define R_BOOKNAME 1
#define R_TITLE 2
#define R_LINE 3
#define R_TYPE 4
#define R_CONTENT 5

//填空题收录 排列
#define F_ID 0
#define F_WORD 1
#define F_FILLBLANK 2
#define F_ANWSER 3
#define F_SENTENCE 4
#define F_EXPLAIN 5
#define F_PROFICIENCY_LEVEL 6
#define F_SHOWED_TIME 7

#define DATAMAX 512
#define C2E 1
#define E2C 2
#define UNFAMILIAR_MODE 3
#define SPELL_MODE (9999)
#define QUIT 99
#define UNFAMILIAR_LIST 1
#define MY_WORDS_LIST 2
#define SPELL_LIST 3

enum mode{
	c2e_mode = 9000,
	e2c_mode,
	unfamiliar_mode,
	spell_mode,
	hardWords_mode,
	show_spell_list,
	show_unfamiliar_list,
	show_myWords_list,
    test_mode_c,    /*测试模式:选择题*/
    test_mode_s,    /*测试模式:填空题*/
    prefix_mode,    /*前缀记忆模式*/
    suffix_mode,     /*后缀记忆模式*/
    rootword_mode    /*词根记忆模式*/
};

enum wordsJudgeType{
	del_word = 1399,
	add_word = 1400,
    omit_word           /*选择题模式删除*/
};

enum queryValType{
	valType_min = 1,
	valType_max
};

/*填空题table查重函数返回值枚举:*/
enum duplicate{
	duplicate_error = -1,   /* duplicate_error:错误 */
	duplicate_false = 0,    /* duplicate_false：没有重复项*/
    duplicate_true = 1      /* duplicate_true：查询到重复项*/
};


typedef unsigned int u_int;

typedef struct{
	int option_choice_num;
	int option_pro_limit;
	int spell_pro_limit;
	int circulate_num;
	bool is_compile_readline;
	bool is_reverse_option;
    bool is_record_fillblank;
    char words_txt[256];
    char reading_txt[256];
    char fillBlank_txt[256];
}CONFIG;

typedef struct{
    bool is_shown;
    unsigned int list_id;
}LIST_BOX,*PLIST_BOX;

typedef struct{
	unsigned int delete_num;
	unsigned int del_id_buf[512];
    /*防止重复删词，做一个已经删除词汇项的缓存*/
    unsigned int delete_wordsType_num;
    char words_buf[50][100];
    /*主动删除熟练词缓存*/
    unsigned int omit_num;
    unsigned int omit_id_buf[100];
}DELETE_LIST,*PDELETE_LIST;

/**************************************begin 前后缀相关 begin************************************************/
#define FIX_LEN (350)/*词条长度限制*/
#define FIX_NUM (300)/*前后缀buff空间大小*/
#define MENU_ITEM_LEN (300)/*多页菜单项的字符串长度限制*/
#define PAGE_LIMIT (30)/*多页菜单的页数限制*/
#define ROW_LIMIT (50)/*多页菜单的行数限制*/
#define MENU_ITEM_LIMIT (PAGE_LIMIT*ROW_LIMIT)
typedef struct{
    char fix[30];
    char descrip[FIX_LEN];
}FIXPAIR;

typedef struct{
    int num;
    FIXPAIR pair[FIX_NUM];
}FIX_GROUP;

enum fixType{
	prefix = 1,
	suffix,
    rootWords
};

FIX_GROUP prefixGroup = {
    .num = 60,
    .pair[0].fix = "a",     .pair[0].descrip = "...的:alike相似的;available 可用的;在...:aside 在旁边",
    .pair[1].fix = "ab",    .pair[1].descrip = "离去:absent 不在的",
    .pair[2].fix = "ac",    .pair[2].descrip = "表加强:accurate 准确的",
    .pair[3].fix = "ad",    .pair[3].descrip = "靠近:admission 准许进入;表加强:admire 倾佩,advocate 提倡",
    .pair[4].fix = "ag",    .pair[4].descrip = "表加强:aggressive 侵略的",
    .pair[5].fix = "al",    .pair[5].descrip = "表加强:allocate 分配",
    .pair[6].fix = "ambi",  .pair[6].descrip = "两,两边:ambiguous 模棱两可",
    .pair[7].fix = "an",    .pair[7].descrip = "表加强:announce 宣布;宣告",
    .pair[8].fix = "ap",    .pair[8].descrip = "表加强:apply 应用;appoint 任命",
    .pair[9].fix = "ar",    .pair[9].descrip = "表加强:arrange 安排",
    .pair[10].fix = "as",   .pair[10].descrip = "表加强:aspect 外表",
    .pair[11].fix = "at",   .pair[11].descrip = "表加强:attempt 试图;attract 吸引",
    .pair[12].fix = "auto", .pair[12].descrip = "自己,自动:automatic 自动的",
    .pair[13].fix = "bene", .pair[13].descrip = "善,好:benefit 使受益",
    .pair[14].fix = "cata", .pair[14].descrip = "下面:catastrophe 大灾难;catalog 目录",
    .pair[15].fix = "col",  .pair[15].descrip = "共同，一起:collect 收集",
    .pair[16].fix = "com",  .pair[16].descrip = "共同:combine (使)结合;command 命令",
    .pair[17].fix = "con",  .pair[17].descrip = "共同:conference 会议;conduct 引导,管理",
    .pair[18].fix = "contra",.pair[18].descrip = "反:contradictory 互相矛盾的",
    .pair[19].fix = "cor",  .pair[19].descrip = "全部:corrupt 腐败的;correct 纠正;改正",
    .pair[20].fix = "de",   .pair[20].descrip = "表加强: declare 宣布,声明; 向下:decline 下降; 否定:desert 遗弃",
    .pair[21].fix = "di",   .pair[21].descrip = "双,二:dioxide 二氧化物; 分开:divide 划分",
    .pair[22].fix = "dis",  .pair[22].descrip = "分开:dismiss 解雇,discriminate 区别对待; 否定:disagree 不同意,discourage 使气馁",
    .pair[23].fix = "e",    .pair[23].descrip = "出:elect (投票)选举",
    .pair[24].fix = "ef",   .pair[24].descrip = "出:effect 效果",
    .pair[25].fix = "em",   .pair[25].descrip = "使:embarrass 使困窘",
    .pair[26].fix = "en",   .pair[26].descrip = "使:enlarge 扩大",
    .pair[27].fix = "ex",   .pair[27].descrip = "经验:experience 经验; 出:explode 爆炸,expose 暴露; 前任:ex-husband 前夫",
    .pair[28].fix = "extra",.pair[28].descrip = "超出:extraordinary 非凡的",
    .pair[29].fix = "fore", .pair[29].descrip = "预先:forecast 预测,预报; 前:forehead 前额",
    .pair[30].fix = "il",   .pair[30].descrip = "否定:illegal 非法的",
    .pair[31].fix = "im",   .pair[31].descrip = "否定:impossible 不可能的",
    .pair[32].fix = "in",   .pair[32].descrip = "否定:independence 独立",
    .pair[33].fix = "inter",.pair[33].descrip = "在...之间:interrupt 打断; 互相:interview 会见,面试",
    .pair[34].fix = "ir",   .pair[34].descrip = "否定:irregular 不规则的",
    .pair[35].fix = "micro",.pair[35].descrip = "微,小:microscope 显微镜",
    .pair[36].fix = "mini", .pair[36].descrip = "小:minimum 最小量",
    .pair[37].fix = "mis",  .pair[37].descrip = "误:mistake 错误,弄错",
    .pair[38].fix = "multi",.pair[38].descrip = "多:multiply 相乘",
    .pair[39].fix = "non",  .pair[39].descrip = "不,无,非:nonsense 无意义的",
    .pair[40].fix = "ob",   .pair[40].descrip = "靠近:obvious 明显的; 表加强:obtain 获得; 逆,反:object 反对",
    .pair[41].fix = "per",  .pair[41].descrip = "自始至终:permanent 永久的",
    .pair[42].fix = "post", .pair[42].descrip = "在后面:postpone 推迟",
    .pair[43].fix = "pre",  .pair[43].descrip = "预先:predict 预言; preview 预习",
    .pair[44].fix = "pro",  .pair[44].descrip = "向前:progress 进步; 支持:provide 提供",
    .pair[45].fix = "re",   .pair[45].descrip = "相反:react 反抗,reject 拒绝; 重新:recycle 回收; 一再:recommend 推荐; 离开:remote 遥远的; 后,回:resign 辞去,辞职",
    .pair[46].fix = "se",   .pair[46].descrip = "分开:separate 分开,分离",
    .pair[47].fix = "semi", .pair[47].descrip = "半:semicircle 半圆",
    .pair[48].fix = "step", .pair[48].descrip = "后,继:stepmother 继母",
    .pair[49].fix = "suf",  .pair[49].descrip = "在下面:suffer 受苦",
    .pair[50].fix = "super",.pair[50].descrip = "在...上面:superior 上级",
    .pair[51].fix = "sur",  .pair[51].descrip = "超过:surplus 剩余",
    .pair[52].fix = "sus",  .pair[52].descrip = "在...下面:suspect 怀疑",
    .pair[53].fix = "sym",  .pair[53].descrip = "共同:sympathy 同情; symphony 交响乐队",
    .pair[54].fix = "tele", .pair[54].descrip = "远:telescope 望远镜",
    .pair[55].fix = "trans",.pair[55].descrip = "转:transform 转变,transport 运输; 越过:transparent 透明的",
    .pair[56].fix = "un",   .pair[56].descrip = "否定:unbelievable 难以置信的; unconditional 无条件的",
    .pair[57].fix = "under",.pair[57].descrip = "在...下:underline 在...下画线; 在...内:underwear 内衣",
    .pair[58].fix = "up",   .pair[58].descrip = "向上:upwards 向上地",
    .pair[59].fix = "with", .pair[59].descrip = "向后:withdraw 撤回"
};

FIX_GROUP suffixGroup = {
    .num = 67,
    .pair[0].fix = "able",  .pair[0].descrip = "(形容词后缀)可...的,有...性质的:portable 轻便的;stable 稳定的",
    .pair[1].fix = "ably",  .pair[1].descrip = "(副词后缀)构成以able结尾的形容词相应副词:probably 很可能,大概",
    .pair[2].fix = "age",   .pair[2].descrip = "(名词后缀)表性质、状态:shortage 短缺",
    .pair[3].fix = "al",    .pair[3].descrip = "(形容词和名词后缀)表人、物、行为;...的:additional 附加的, criminal 罪犯",
    .pair[4].fix = "an",    .pair[4].descrip = "(形容词和名词后缀)表人;...的:American 美国人(的)",
    .pair[5].fix = "ance",  .pair[5].descrip = "(名词后缀)表性质、状态、动作:significance 重要性",
    .pair[6].fix = "ant",   .pair[6].descrip = "(形容词和名词后缀)表人或物;...的:applicant 申请人,significant 重要的",
    .pair[7].fix = "ary",   .pair[7].descrip = "(名词和形容词后缀)表人、物、场所;...的:secretary 秘书, necessary 必要的",
    .pair[8].fix = "ate",   .pair[8].descrip = "(动词、名词、形容词后缀)使...;表人;...的:calculate 计算, graduate 毕业生, private 个人的",
    .pair[9].fix = "atic",  .pair[9].descrip = "(形容词后缀)...的:systematic 系统的",
    .pair[10].fix = "ation",.pair[10].descrip = "(名词后缀)表状态、动作、过程或结果:situation 状况,形势; generation 代",
    .pair[11].fix = "ative",.pair[11].descrip = "(形容词后缀)...的:alternative 选择性的",
    .pair[12].fix = "ator", .pair[12].descrip = "(名词后缀)表人或物:creator 创造者;elevator 电梯",
    .pair[13].fix = "dom",  .pair[13].descrip = "(名词后缀)表状态、身份或领域:freedom 自由",
    .pair[14].fix = "ed",   .pair[14].descrip = "(形容词后缀)...的:surprised 惊奇的",
    .pair[15].fix = "ee",   .pair[15].descrip = "(名词后缀)表人:employee 雇员",
    .pair[16].fix = "eer",  .pair[16].descrip = "(名词后缀)表人:engineer 工程师",
    .pair[17].fix = "en",   .pair[17].descrip = "(动词、名词、形容词后缀)使;似...的:sharpen 削尖, golden 金黄色的",
    .pair[18].fix = "ence", .pair[18].descrip = "(名词后缀)表性质、状态或行为:silence 安静",
    .pair[19].fix = "ency", .pair[19].descrip = "(名词后缀)表性质、状态或行为:emergency 紧急情况",
    .pair[20].fix = "ent",  .pair[20].descrip = "(形容词后缀)...的:different 不同的",
    .pair[21].fix = "er",   .pair[21].descrip = "(名词后缀)表人或物:computer 计算机",
    .pair[22].fix = "ern",  .pair[22].descrip = "(形容词后缀)表方位:southern 南方的",
    .pair[23].fix = "ess",  .pair[23].descrip = "(名词后缀)女性,雌性:hostess 女主人; lioness 雌狮",
    .pair[24].fix = "etic", .pair[24].descrip = "(形容词后缀)...的:energetic 精力充沛的",
    .pair[25].fix = "ety",  .pair[25].descrip = "(名词后缀)表性质、状态:variety 种类; anxiety 焦虑",
    .pair[26].fix = "faction",.pair[26].descrip = "(名词后缀)表情况、状态或行为:satisfaction 满意",
    .pair[27].fix = "fic",  .pair[27].descrip = "(形容词后缀)...的:scientific 科学的",
    .pair[28].fix = "ful",  .pair[28].descrip = "(形容词和名词后缀)充满的,有...性质的:successful 成功的;hopeful 有希望的",
    .pair[29].fix = "fy",   .pair[29].descrip = "(动词后缀)使...:satisfy 使满意",
    .pair[30].fix = "hood", .pair[30].descrip = "(名词后缀)表性质、状态:childhood 同年",
    .pair[31].fix = "ial",  .pair[31].descrip = "(形容词后缀)...的:facial 面部的",
    .pair[32].fix = "ian",  .pair[32].descrip = "(形容词和名词后缀)...的,...人:Australian 澳大利亚人(的)",
    .pair[33].fix = "ibility",.pair[33].descrip = "(名词后缀)可能性: possibility 可能性",
    .pair[34].fix = "ible", .pair[34].descrip = "(形容词后缀)可...的:accessible 可进入的",
    .pair[35].fix = "ibly", .pair[35].descrip = "(副词后缀)...地:terribly 可怕地",
    .pair[36].fix = "ic",   .pair[36].descrip = "(形容词和名词后缀)...的;表人:economic 经济的",
    .pair[37].fix = "ical", .pair[37].descrip = "(形容词后缀)...的:tropical 热带的",
    .pair[38].fix = "ician",.pair[38].descrip = "(名词后缀)表人:politician 政治家",
    .pair[39].fix = "ics",  .pair[39].descrip = "(名词后缀)表学科名称:physics 物理学",
    .pair[40].fix = "id",   .pair[40].descrip = "(形容词后缀)...的:acid 酸的",
    .pair[41].fix = "ier",  .pair[41].descrip = "(名词后缀)表人或物:cashier 出纳;barrier 栅栏",
    .pair[42].fix = "ile",  .pair[42].descrip = "(形容词后缀)...的:mobile 活动的,可移动的",
    .pair[43].fix = "ish",  .pair[43].descrip = "(形容词和动词后缀)如...的:selfish 自私的;polish 擦亮",
    .pair[44].fix = "ism",  .pair[44].descrip = "(名词后缀)主义,学说:communism 共产主义",
    .pair[45].fix = "ist",  .pair[45].descrip = "(名词后缀)...主义者,从事...的人:specialist 专科医生;socialist 社会主义者",
    .pair[46].fix = "ition",.pair[46].descrip = "(名词后缀)表性质、行为:competition 比赛,竞赛",
    .pair[47].fix = "ity",  .pair[47].descrip = "(名词后缀)表性质、状态:ability 能力",
    .pair[48].fix = "ive",  .pair[48].descrip = "(形容词和名词后缀)...的:subjective 主观的",
    .pair[49].fix = "ize",  .pair[49].descrip = "(动词后缀)使...化:apologize 道歉;recognize 认出",
    .pair[50].fix = "less", .pair[50].descrip = "(形容词后缀)不,没有:hopeless 没有希望的",
    .pair[51].fix = "ly",   .pair[51].descrip = "(形容词和副词后缀)...的,每...的;...地:friendly 友好的;carefully 小心地",
    .pair[52].fix = "ment", .pair[52].descrip = "(名词后缀)表物、行为或状态:punishment 惩罚",
    .pair[53].fix = "ness", .pair[53].descrip = "(名词后缀)表性质或状态:kindness 仁慈;friendliness 友好",
    .pair[54].fix = "or",   .pair[54].descrip = "(名词后缀)表人:editor 编辑;educator 教育家",
    .pair[55].fix = "ous",  .pair[55].descrip = "(形容词后缀)...的:various 各种各样的",
    .pair[56].fix = "ship", .pair[56].descrip = "(名词后缀)表状态、性质或身份:friendship 友谊",
    .pair[57].fix = "sion", .pair[57].descrip = "(名词后缀)表行为、状态:expression 表达",
    .pair[58].fix = "some", .pair[58].descrip = "(形容词后缀)令人...的:tiresome 令人讨厌的",
    .pair[59].fix = "th",   .pair[59].descrip = "(序数词和名词后缀)第...;表性质:sixth 第六;warmth 温暖,暖和",
    .pair[60].fix = "tic",  .pair[60].descrip = "(形容词后缀)...的:fantastic 极好的,美妙的",
    .pair[61].fix = "tion", .pair[61].descrip = "(名词后缀)表行为或状态:instruction 说明;intention 意图",
    .pair[62].fix = "tude", .pair[62].descrip = "(名词后缀)表状态:altitude 高度,高处",
    .pair[63].fix = "ual",  .pair[63].descrip = "(形容词后缀)...的:punctual 准时的",
    .pair[64].fix = "ure",  .pair[64].descrip = "(名词后缀)表行为或状态:agriculture 农业",
    .pair[65].fix = "ward,wards",.pair[65].descrip = "(形容词和副词后缀)表方向或方位:up-ward(s) 向上地;forward 向前地",
    .pair[66].fix = "y",    .pair[66].descrip = "(形容词和名词后缀)有...的,多...的;表性质、状态;场所:discovery 发现;sunny 有阳光的;hairy 多毛的"
};

FIX_GROUP roofGroup = {
    .num = 114,
    .pair[1].fix = "acu",   .pair[1].descrip = "尖端:acute 尖锐的",
    .pair[2].fix = "ag",    .pair[2].descrip = "做,行动:agency 代理处;agenda 议程",
    .pair[3].fix = "agri",  .pair[3].descrip = "田地,农业:agriculture 农业",
    .pair[4].fix = "ann",   .pair[4].descrip = "年:annual 每年的",
    .pair[5].fix = "astro,aster",.pair[5].descrip = "星星,天体:astronomy 天文学;disaster 灾难",
    .pair[6].fix = "audi",  .pair[6].descrip = "听:audible 可听见的;audience 观众,听众",
    .pair[7].fix = "bi,bio",.pair[7].descrip = "生命:biology 生物学;biography 传记",
    .pair[8].fix = "brilli",.pair[8].descrip = "发光:brilliant 闪耀的",
    .pair[9].fix = "ceed,cess",.pair[9].descrip = "走:succeed 成功;access 进入; process 程序;accessible 易接近的",
    .pair[10].fix = "ceive", .pair[10].descrip = "拿,抓:receive 收到",
    .pair[11].fix = "cept",  .pair[11].descrip = "拿,抓:accept 接受;concept 概念,观念;except 除...之外;reception 接待",
    .pair[12].fix = "circ,cycl",.pair[12].descrip = "圆,圈,环:circle 圆圈;cycle 循环",
    .pair[13].fix = "cid",  .pair[13].descrip = "切,落下:accident 意外;incident 事件",
    .pair[14].fix = "cline",.pair[14].descrip = "倾斜:decline 下降;衰败",
    .pair[15].fix = "clud", .pair[15].descrip = "关闭:conclude 完成,结束;include 包括,包含",
    .pair[16].fix = "cogn", .pair[16].descrip = "知道:recognize 认出,承认",
    .pair[17].fix = "cred", .pair[17].descrip = "相信:credit 信赖",
    .pair[18].fix = "cur,curr",.pair[18].descrip = "跑,发生:occur 发生;current 当前的;currency 货币;curriculum 课程",
    .pair[19].fix = "cuse", .pair[19].descrip = "理由:accuse 谴责",
    .pair[20].fix = "dic,dict",.pair[20].descrip = "说:dictionary 字典;predict 预言,预报",
    .pair[21].fix = "duc,duct",.pair[21].descrip = "引导,带来:educate 教育;conduct 引导",
    .pair[22].fix = "equ",  .pair[22].descrip = "平等,相等:equal 相等的;adequate 足够的,适当的",
    .pair[23].fix = "fect", .pair[23].descrip = "做:effect 效果",
    .pair[24].fix = "fend", .pair[24].descrip = "打击:defend 防御;防护",
    .pair[25].fix = "fer",  .pair[25].descrip = "带来,拿:conference 会议;refer 提到;differ 有区别;suffer 受苦",
    .pair[26].fix = "fic,fit",.pair[26].descrip = "做:beneficial 有益的;benefit 使受益:",
    .pair[27].fix = "flect,flex",.pair[27].descrip = "弯曲:reflect 反射,反映;flexible 柔软的,灵活的",
    .pair[28].fix = "flu",  .pair[28].descrip = "流动:fluent 流畅的;influence 影响",
    .pair[29].fix = "fuse", .pair[29].descrip = "流:confuse 使糊涂;搞乱",
    .pair[30].fix = "gener",.pair[30].descrip = "产生:generous 慷慨的",
    .pair[31].fix = "grad", .pair[31].descrip = "级:graduate 毕业",
    .pair[32].fix = "gram,graph",.pair[32].descrip = "写,画,文:diagram 图,表;telegram 电报;photograph 照片",
    .pair[33].fix = "gress",.pair[33].descrip = "行走:progress 进步,上进;aggressive 侵略的",
    .pair[34].fix = "hes",  .pair[34].descrip = "粘附:hesitate 犹豫,踌躇",
    .pair[35].fix = "hibit",.pair[35].descrip = "拿住,持着:prohibit 禁止,阻止",
    .pair[36].fix = "ident",.pair[36].descrip = "相同:identify 一致",
    .pair[37].fix = "init", .pair[37].descrip = "开始:initial 开始的,最初的",
    .pair[38].fix = "ject", .pair[38].descrip = "投,扔:object 反对;reject 拒绝",
    .pair[39].fix = "jud",  .pair[39].descrip = "判断:prejudice 偏见",
    .pair[40].fix = "jur",  .pair[40].descrip = "法律:injure 伤害",
    .pair[41].fix = "lect", .pair[41].descrip = "收集,讲:collect 收集;lecture 讲课",
    .pair[42].fix = "lect,leg",.pair[42].descrip = "选:select 选择,挑选;elect(投票)选举;elegant 文雅的,雅致的",
    .pair[43].fix = "leg",  .pair[43].descrip = "法律:legal 法律的",
    .pair[44].fix = "lim",  .pair[44].descrip = "限制:limit 限制,限定",
    .pair[45].fix = "liter",.pair[45].descrip = "文字,字母:literary 文学的;literature 文学",
    .pair[46].fix = "loc",  .pair[46].descrip = "地方:allocate 分配,配给;local 地方的",
    .pair[47].fix = "log",  .pair[47].descrip = "apologize 道歉;dialogue 对话:",
    .pair[48].fix = "main", .pair[48].descrip = "留:remain 余下,留下",
    .pair[49].fix = "maj",  .pair[49].descrip = "大:major 主要的",
    .pair[50].fix = "mand", .pair[50].descrip = "命令:command 命令;demand 要求",
    .pair[51].fix = "mat",  .pair[51].descrip = "动:automatic 自动的",
    .pair[52].fix = "medi", .pair[52].descrip = "中间:medium 中间的;媒介",
    .pair[53].fix = "memor",.pair[53].descrip = "记忆:memory 记忆;memorial 纪念物,纪念碑",
    .pair[54].fix = "ment", .pair[54].descrip = "想;心智:mental 精神的,脑力的;mention 提及,说起",
    .pair[55].fix = "mir",  .pair[55].descrip = "惊奇:admire 倾佩,羡慕;miracle 奇迹",
    .pair[56].fix = "miss,mit",.pair[56].descrip = "送:admission 准许进入;admit 承认;commitment 献身,投入;dismiss 解雇",
    .pair[57].fix = "mob",  .pair[57].descrip = "动:mobile 活动的,可移动的",
    .pair[58].fix = "mod",  .pair[58].descrip = "方式;风度:modest 谦虚的",
    .pair[59].fix = "mor",  .pair[59].descrip = "道德:moral 道德的",
    .pair[60].fix = "mot,mote",.pair[60].descrip = "动,移动:promote 促进,提升;remote 遥远的",
    .pair[61].fix = "noc",  .pair[61].descrip = "伤害:innocent 纯真的",
    .pair[62].fix = "numer",.pair[62].descrip = "数量:numerous 多的,大量的",
    .pair[63].fix = "oper", .pair[63].descrip = "工作:operate 操作;operation 手术",
    .pair[64].fix = "optim",.pair[64].descrip = "最好:optimistic 乐观的",
    .pair[65].fix = "par",  .pair[65].descrip = "相等:separate (使)分开,(使)分离",
    .pair[66].fix = "pass", .pair[66].descrip = "感情:passive 被动的;消极的",
    .pair[67].fix = "pend", .pair[67].descrip = "悬,挂:depend 取决于",
    .pair[68].fix = "pens", .pair[68].descrip = "花费:expense 费用,支出",
    .pair[69].fix = "pet",  .pair[69].descrip = "追求,寻求:compete 竞赛;competence 能力",
    .pair[70].fix = "ple",  .pair[70].descrip = "满,填满:complete 完成;结束",
    .pair[71].fix = "ply",  .pair[71].descrip = "重叠:apply 应用;multiply 增加;supply 供给",
    .pair[72].fix = "port", .pair[72].descrip = "拿、运:export 出口;transport 运输",
    .pair[73].fix = "pos,posit",.pair[73].descrip = "放:oppose 反对;positive 积极的;expose 暴露",
    .pair[74].fix = "preci", .pair[74].descrip = "价值:appreciate 欣赏;precious 宝贵的,珍贵的",
    .pair[75].fix = "prim,prem",.pair[75].descrip = "第一,首要:primary 首要的;premier 首相,总理",
    .pair[76].fix = "priv",  .pair[76].descrip = "私有:private 私人的;私营的",
    .pair[77].fix = "puls",  .pair[77].descrip = "驱动,推:compulsory 义务的",
    .pair[78].fix = "punct", .pair[78].descrip = "刺:punctual 准时的",
    .pair[79].fix = "physic",.pair[79].descrip = "自然:physical 客观存在的",
    .pair[80].fix = "rect",  .pair[80].descrip = "正,直:correct 改正,纠正;rectangle 长方形",
    .pair[81].fix = "rupt",  .pair[81].descrip = "断裂:corrupt 腐败的;abrupt 突然的,意外的",
    .pair[82].fix = "sacr",  .pair[82].descrip = "神圣的:sacred 庄严的,神圣的;sacrifice 牺牲",
    .pair[83].fix = "scribe",.pair[83].descrip = "写:subscribe 订阅;describe 描写",
    .pair[84].fix = "sect",  .pair[84].descrip = "切割:insect 昆虫",
    .pair[85].fix = "sembl", .pair[85].descrip = "类似:resemble 像,类似:",
    .pair[86].fix = "sens",  .pair[86].descrip = "感觉:sensitive 敏感的",
    .pair[87].fix = "sert",  .pair[87].descrip = "加入,插,放:desert 遗弃;insert 插入",
    .pair[88].fix = "sist,stat,stant",.pair[88].descrip = "站:consist 由...组成;consistent 一致的;constant 不断的;status 身份,地位",
    .pair[89].fix = "solut", .pair[89].descrip = "松开:absolute 完全的",
    .pair[90].fix = "spect", .pair[90].descrip = "看:aspect 外表;respect 尊重;inspect 检查,观察",
    .pair[91].fix = "sphere",.pair[91].descrip = "球体:atmosphere 大气",
    .pair[92].fix = "struct",.pair[92].descrip = "建立:construct 建造,构造",
    .pair[93].fix = "sume",  .pair[93].descrip = "拿,取:assume 承担",
    .pair[94].fix = "surd",  .pair[94].descrip = "不合理的:absurd 荒谬的",
    .pair[95].fix = "tain",  .pair[95].descrip = "拿住:contain 包含;包括",
    .pair[96].fix = "tach",  .pair[96].descrip = "钉:attach 贴上,系上",
    .pair[97].fix = "tempor",.pair[97].descrip = "时间:contemporary 同时代的;temporary 暂时的",
    .pair[98].fix = "tend,tens",.pair[98].descrip = "伸展:tendency 倾向,趋势;tension 拉紧,张力",
    .pair[99].fix = "tent",  .pair[99].descrip = "张开:intention 意图,目的",
    .pair[100].fix = "tract",.pair[100].descrip = "拉:attract 吸引;abstract 概要",
    .pair[101].fix = "tribute",.pair[101].descrip = "给予:contribute 捐献",
    .pair[102].fix = "turb", .pair[102].descrip = "搅乱:disturb 扰乱",
    .pair[103].fix = "urb",  .pair[103].descrip = "城市:urban 城市的",
    .pair[104].fix = "urg",  .pair[104].descrip = "驱动,驱使:urge 催促,力劝;urgent 急迫的,紧急的",
    .pair[105].fix = "vac",  .pair[105].descrip = "空:vacant 空的",
    .pair[106].fix = "vail", .pair[106].descrip = "价值:available 可用的",
    .pair[107].fix = "vent", .pair[107].descrip = "来:adventure 冒险;prevent 阻止",
    .pair[108].fix = "vers,vert",.pair[108].descrip = "转:advertise 做广告;anniversary 周年纪念;controversial 争议的;diverse 不同的,多种多样的;universe 宇宙",
    .pair[109].fix = "vis,vid",.pair[109].descrip = "看:advise 劝告;evident 明显的",
    .pair[110].fix = "vit,viv,vive",.pair[110].descrip = "生命:vital 生死攸关的;vivid 生动的;survive 比...活动长",
    .pair[111].fix = "voc",  .pair[111].descrip = "声音,喊叫:advocate 提倡;鼓吹",
    .pair[112].fix = "void", .pair[112].descrip = "空:avoid 避免,躲开",
    .pair[113].fix = "wis,wit",.pair[113].descrip = "知道,了解:wisdom 智慧;witness 目击,作证"
};
void showFixGroup(FIX_GROUP* fixgroup);
/*前后缀菜单项字符串拼接函数*/
void composeFixMenuItem(FIX_GROUP* fixgroup,char item[][FIX_LEN],int fixType,int* fitNum,int* map);
/*前后缀在数据库中出现的匹配的词条数查询*/
int searchFixNum(sqlite3* db,char* fix,int* num,int fixType);
//实现冒泡降序排序算法的函数，list[num] 为待排序数组
void Bubble_sort(int* list,int num,int* map);
/****************************************end 前后缀相关 end*******************************************************/

void do_ui_display(sqlite3* db);
void do_listRecite(sqlite3* db,int _start_id,int _num,int options,int* correct_n,int* err_n);
int* min_select(int* in_array,int* out_array,int* out_id_array,int total,int select_num,int min_val);
int do_example_sentence(sqlite3* db,int _num);
int do_spell_mode(sqlite3* db,int type);
int optionsGenerator(sqlite3* db,char** buf,const int list_num,const int cloumn_num,PLIST_BOX list_box,int options);
unsigned int secondMenu();			//二级菜单
int strPosition(int strType,int strRow,int ncol);
int strPosition_fillBlank(int strType,int strRow,int ncol);
int  trans_user_answer_form(char user_answer);
int getReciteLocation(char* _id_start,char* _num,char* _recv_buf,char* instruction,bool is_just_num);
int console_ex(sqlite3* db);
int proficiency_level_record(sqlite3* db,bool is_correct);
int spell_level_record(sqlite3* db,bool is_correct,int type);
int show_list(sqlite3* db,int list_type);
int do_search_word(sqlite3 *db,char *word,char* eng_descrip);
int add_words_list_judge(const int word_id,const char* words);
int delete_words_list_judge(sqlite3 *db,const int word_id,const char* words,DELETE_LIST* del_list);
void check_myWordsList(sqlite3* db);
char** find_record_by_ID(const int id,char** result,int* nrow,int* ncloumn);
char** find_record_in_myWordsList_by_ID(const int id,bool* isProficiency);//根据id查找生词表中的词汇项
void error_list_init();
void error_word_record();
int show_error_record();
int show_progress(sqlite3 *db);
int readMode(int markId);
int getBookmarkById(int markId,char* tableBook_name);
int setBookmarkById(int markId,int newMarkLine);
int multiWordsJudge(char* words,int judgeType,DELETE_LIST * del_list);
int del_words(DELETE_LIST* del_list,int options);
char* excludeNewLineSymbol(char* buf);
char* get_date(char* m_date);//获取当前系统时间函数
int check_duplicate(sqlite3* db, char* words,int s_id);
/* 随机数生成函数,生成（1 ~ _num）区间范围的随机数，每次执行返回一个随机数，已经抽取到的随机数将不会再被抽到*/
int createRandomSeq(PLIST_BOX list_box,int _num,bool isFirstTime);
int check_is_omit(DELETE_LIST * del_list);/*选择题模式检查是否为已删除词汇*/

/*****************************************menu相关函数定义***************************************************************************/
#include <stdio.h>
#include <stdbool.h>
#ifdef _WIN32 //Linux platform
    #include <conio.h>
#else
    #include <termios.h>
#endif
 
char get1char(void)
{
 
#ifdef _WIN32
        // Do nothing
#else   // 保存并修改终端参数
    struct termios stored_settings;
    struct termios new_settings;
    tcgetattr (0, &stored_settings);
    new_settings = stored_settings;
    new_settings.c_lflag &= (~ICANON);
    new_settings.c_cc[VTIME] = 0;
    new_settings.c_cc[VMIN] = 1;
    tcsetattr (0, TCSANOW, &new_settings);
#endif
 
    int ret = 0;
    char c;
 
#ifdef _WIN32
    c = getch();
#else
    c = getchar();
    putchar('\b'); // 删除回显
#endif
 
    // printf("input:  [%c]\n", c);
 
#ifdef _WIN32
    // Do nothing
#else
    tcsetattr (0, TCSANOW, &stored_settings); // 恢复终端参数
#endif
 
    return c; 
}

// 上移光标
#define MOVEUP(x) printf("\033[%dA", (x))
 
// 下移光标
#define MOVEDOWN(x) printf("\033[%dB", (x))
 
// 左移光标
#define MOVELEFT(y) printf("\033[%dD", (y))
 
// 右移光标
#define MOVERIGHT(y) printf("\033[%dC",(y))

// 隐藏光标
#define HIDE_CURSOR() printf("\033[?25l")
// 显示光标
#define SHOW_CURSOR() printf("\033[?25h")

/*
* description:单列菜单接口(内置循环)
* param: option:菜单选项二维数组  optionNum:有几个需要组成的菜单选项
* return val:用户选中的菜单项索引(0~optionNum-1)
*/
int menuOfReadMode(char** option,char optionNum);
/*
*可翻页菜单(option传参方式和menuOfReadMode不同，不能兼容)
*isSetbackEntrance 表示需要在多页菜单每页的最后一项设置返回选项，函数返回0代表返回选项被选中
*/
int menuOfReadMode_vectorParam(char option[][FIX_LEN],char optionNum,char rowNum,bool isSetbackEntrance);

/*
* description:多列列菜单接口(可单列)(外置循环)
* param: item:菜单选项二维数组  
*        itemNum:有几个需要组成的菜单选项
*        colNum:需要几列
*        pos：二维坐标数组，用以返回当前的item坐标值
*        isChoose:是否选中,上层调用接口用来判断是否跳出循环
*        ctrl：传入用户输入的控制字符
* return: pos,二维坐标数组，用以返回当前的item坐标值
*/
char* menu(char** item,char itemNum,char colNum,char* pos,bool* isChoose,char ctrl)
{
    // pos[0] = 0;// row position(x)
    // pos[1] = 0;// col position(y)
    int rowNum = itemNum % colNum == 0 ? itemNum/colNum : itemNum/colNum + 1;
    char buf[100] = {0};
    char p_tmp[2] = {0};//选项坐标缓冲
    p_tmp[1] = -1;

    //识别控制字符
    if('w' == ctrl) pos[0]--;
    if('s' == ctrl) pos[0]++;
    if('a' == ctrl) pos[1]--;
    if('d' == ctrl) pos[1]++;
    if(' ' == ctrl) *isChoose = true;
    //行限位
    if(pos[0] < 0) pos[0] = 0;
    if(pos[0] > rowNum-1) pos[0] = rowNum-1;
    //列限位
    if(pos[1] < 0) pos[1] = 0;
    if(pos[1] > colNum-1) pos[1] = colNum-1;

    for(int i = 0; i < itemNum; i++){    
        p_tmp[1]++;

        if(i == 0) printf("\r\033[K");//整行清除
        if(pos[0] == p_tmp[0] && pos[1] == p_tmp[1])
            printf("* (%d,%d)%s     ",p_tmp[0],p_tmp[1],item[i]);
        else
            printf("  (%d,%d)%s     ",p_tmp[0],p_tmp[1],item[i]);
        if((i+1) % colNum == 0){//换行
            p_tmp[0]++;
            p_tmp[1] = -1;
            if(i != (itemNum -1) ) {
                printf("\n");
                printf("\r\033[K");//整行清除
            }
        } 
    }
    fflush(stdout);//立刻输出
    MOVEUP(rowNum-1);
    // printf(" rowNum:%d\n",rowNum);

    return pos;
}

/*****************************************例句填空功能相关函数定义***************************************************************************/

#define READE_SIZE (4096)//例句预留buffer大小(一行)

typedef struct {
    int num;
    char explanation[50][READE_SIZE];
    char sentence[50][READE_SIZE];
}EXAMPLE_OF_SENTENCE_;
int search_example(char *msg, int size, char *words,EXAMPLE_OF_SENTENCE_* example);
/*首字母大写转换函数*/
int changeInitialCapitalization(char* words);
/*
* description:从例句中扣出目标单词，做成填空题形式
* sen:原例句
* words:目标单词
* outSen:扣除单词后的填空题
* extForm:从例句中扣出的单词(可能变形)
* return : 0 成功        -1 识别到不规则动词变化，失败
*/
int extract_words_from_exampleSentence(char* sen,char* words,char* outSen,char* extForm,int outSen_size,int extForm_size);
/*****************************************阅读/词汇增加接口定义***************************************************************************/
/*词汇*/
int words_add2dataBase(sqlite3 *db,char* txt_dir);
char* word_extract(const char* origin_buf);
char* descrip_extract(const char* origin_buf);
char* pronounce_extract(const char* origin_buf);
bool isThereHasSlash(const char* origin_buf);
/*阅读*/
/*用于每次添加新的阅读材料前获取最大id,当前line.新的阅读材料在此基础上进行累加*/
int find_max_id(sqlite3 *db,int markId,char* tableBook_name,int* line);
int handle_slash(char* buf,int len);
int judge_insertType(int type,int* bookId,char* bookname);
int reading_add2dataBase(sqlite3 *db,char* txt_dir,int type);
int ReadingMaterial_extract(sqlite3 *db,char* buf,bool* isNewChapter,int* line,char* bookname,int markId);

/*****************************************selite3操作接口集合***************************************************************************/
void printSqliteQueryResult(char **result,int nrow,int ncloumn);/*打印sqlite3查询到的table详细信息*/
int get_polarizationVal_fromTable(sqlite3* db,char* col_name,char* table_name,int val_type);/*在table中获取最大/最小值*/
#endif //__MISC_H__